<template>
	<div>
		<!-- 收货地址页 -->
		<address-item v-for="v in address" :key="v.aid" :address="v"/>
		<!-- 添加新地址 -->
		<div class="add_address">添加新地址</div>
	</div>
</template>

<script>
import AddressItem from '@/components/AddressItem.vue'
	export default {
  		components: { AddressItem },
		props:['userId'],
		data() {
			return {
				address: [] //用户收货地址
			}
		},
		methods:{
			// 获取收货地址
			getUserAddress(){
				return new Promise((resolve,reject)=>{
					const url=`api/users/user_address?sid=${this.userId}`
					this.axios.get(url)
					.then(res => resolve(res.data))
					.catch(err => reject(err))
				})
				
			}
		},
		mounted(){
			this.getUserAddress().then(res =>this.address=res.result)
		}
	}
</script>

<style lang="scss" scoped>
.add_address {
	background-color: #9a4145;
	color: #fff;
	padding: 0.615em 1.25em;
	border-radius: 3.125em;
	position: fixed;
	bottom: 2.5em;
	left: calc(50% - 4em)
}
</style>